//import com.sun.image.codec.jpeg.JPEGCodec;
//import com.sun.image.codec.jpeg.JPEGEncodeParam;
//import com.sun.image.codec.jpeg.JPEGImageEncoder;
//import net.coobird.thumbnailator.Thumbnails;
////import org.springframework.mock.web.MockMultipartFile;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.imageio.ImageIO;
//import javax.imageio.ImageReader;
//import javax.imageio.stream.FileImageInputStream;
//import javax.imageio.stream.ImageInputStream;
//import java.awt.*;
//import java.awt.image.BufferedImage;
//import java.io.*;
//import java.util.Iterator;
//import java.util.UUID;
//import java.util.logging.Level;
//import java.util.logging.Logger;
//
///**
// *
// * @author Jiangpin
// */
//public class Img_Thumbnail
//
//{
//    public static void main(String[] args) throws IOException {
//        String path = "d:\\abc.jpeg";
//        File file = new File(path);
//        System.out.println("第1种方法使用的时间：");
//        long s1 = System.currentTimeMillis();
//        System.out.println(getResolution1(file));
//        long l1 = System.currentTimeMillis();
//        System.out.println((l1 - s1)+"ms");
//        System.out.println("******************************");
//        System.out.println("第2种方法使用的时间：");
//        long s2 = System.currentTimeMillis();
//        getResolution2(path);
//        long l2 = System.currentTimeMillis();
//        System.out.println((l2 - s2)+"ms");
//    }
//
//    private static void getResolution2(String path) throws IOException {
//        String s = getImageDim(path).toString();
//        String w = s.substring(s.indexOf("=") + 1, s.indexOf(","));
//
//        File file = new File(path);
//
//        FileInputStream fileInputStream = new FileInputStream(file);
//        MultipartFile imageFile = new MockMultipartFile("copy" + file.getName(), file.getName(), "image/jpeg", fileInputStream);
//        String uuid = UUID.randomUUID().toString();
//        //拼接后台文件名称
//        String fileSuffix = getFileSuffix(path);
//        String thumbnailPathName =  path.substring(0,path.indexOf("."))
//        + uuid + "_small." + fileSuffix;
//        if(thumbnailPathName.contains(".png")){
//            thumbnailPathName = thumbnailPathName.replace(".png", ".jpg");
//        }
////        long size = imageFile.getSize();
//        double scale = 1.0d ;
//        Double aDouble = new Double(w);
//        scale = 1080 / aDouble;
////        if(size >= 1440 * 1080){
////            if(size > 0){
////                scale = (1440 * 1080f) / size  ;
////            }
////        }
//        String thumbnailFilePathName =  File.separator + thumbnailPathName;
//
//        try {
//            //added by chenshun 2016-3-22 注释掉之前长宽的方式，改用大小
////            Thumbnails.of(filePathName).size(width, height).toFile(thumbnailFilePathName);
////            if(size < 200*1024){
////                Thumbnails.of(path).scale(1f).outputFormat("jpg").toFile(thumbnailFilePathName);
////            }else{
//                Thumbnails
//                        .of(path)
//                        .scale(scale)
//                        .outputQuality(1f)
//                        .outputFormat("jpg")
//                        .toFile(path);
////                        .toFile(thumbnailFilePathName);
////            }
//        } catch (Exception e1) {
////            return new BaseResult(false, "操作失败", e1.getMessage());
//            e1.printStackTrace();
//        }
//
//
//    }
//
////    private static MultipartFile getFile(File file) {
//////        FileItem fileItem = new DiskFileItem();
////        byte[] buffer = new byte[4096];
////        int n;
////        try(InputStream inputStream = new FileInputStream(file); OutputStream os = fileItem.getOutputStream()){
////
////        }catch (IOException e){e.printStackTrace();}
////        return null;
////    }
//
//    private static boolean getResolution1(File file) {
//        return false;
//    }
//    public static Dimension getImageDim(String path) {
//        Dimension result = null;
//        String suffix = getFileSuffix(path);
//        //解码具有给定后缀的文件
//        Iterator<ImageReader> iter = ImageIO.getImageReadersBySuffix(suffix);
//        System.out.println(ImageIO.getImageReadersBySuffix(suffix));
//        if (iter.hasNext()) {
//            ImageReader reader = iter.next();
//            try {
//                ImageInputStream stream = new FileImageInputStream(new File(path));
//                reader.setInput(stream);
//                int width = reader.getWidth(reader.getMinIndex());
//                int height = reader.getHeight(reader.getMinIndex());
//                result = new Dimension(width, height);
//            } catch (IOException e) {
//                e.printStackTrace();
//            } finally {
//                reader.dispose();
//            }
//        }
//        System.out.println("getImageDim:" + result);
//        return result;
//    }
//    /**
//     * 获得图片的后缀名
//     * @param path
//     * @return
//     */
//    private static String getFileSuffix(final String path) {
//        String result = null;
//        if (path != null) {
//            result = "";
//            if (path.lastIndexOf('.') != -1) {
//                result = path.substring(path.lastIndexOf('.'));
//                if (result.startsWith(".")) {
//                    result = result.substring(1);
//                }
//            }
//        }
//        System.out.println("getFileSuffix:" + result);
//        return result;
//    }
//}